#ifndef BASICIO_H
#define BASICIO_H

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "driver/gpio.h"
#include "driver/adc.h"
#include "esp_adc_cal.h"

/*PineWatch-4202 PinDef*/
#define MAX668_SD   9
#define HV_CLK      21
#define HV_DIN      19
#define HV_LE       22
#define OUTPP_PIN   (1ULL << MAX668_SD) | (1ULL << HV_CLK) | (1ULL << HV_DIN) | (1ULL << HV_LE)

#define IMU_SCLK    23
#define IMU_SDA     18
#define OUTOD_PIN   (1ULL << IMU_SCLK) | (1ULL << IMU_SDA)


#define VBAT_ADC        4
#define VBAT_ADC2_CH    0
#define INFLOATING_PIN  (1ULL << VBAT_ADC)

#define IMU_INT1    14
#define IMU_INT2    27
#define CHRG_STAT   10
#define INPULLDOWN_PIN  (1ULL << IMU_INT1) | (1ULL << IMU_INT2) | (1ULL << CHRG_STAT)

#define HV_CLK_H    gpio_set_level(HV_CLK, 1)
#define HV_CLK_L    gpio_set_level(HV_CLK, 0)
#define HV_DIN_H    gpio_set_level(HV_DIN, 1)
#define HV_DIN_L    gpio_set_level(HV_DIN, 0)
#define HV_LE_H     gpio_set_level(HV_LE, 1)
#define HV_LE_L     gpio_set_level(HV_LE, 0)

#define IMU_SCLK_H  gpio_set_level(IMU_SCLK, 1)
#define IMU_SCLK_L  gpio_set_level(IMU_SCLK, 0)
#define IMU_SDA_H   gpio_set_level(IMU_SDA, 1)
#define IMU_SDA_L   gpio_set_level(IMU_SDA, 0)

#define HV_EN       gpio_set_level(MAX668_SD, 1)
#define HV_SD       gpio_set_level(MAX668_SD, 0)

#define ReadVBAT    0
#define ReadINT1    gpio_get_level(IMU_INT1)
#define ReadINT2    gpio_get_level(IMU_INT2)

#define delay(uint32_t)    vTaskDelay(uint32_t / portTICK_PERIOD_MS)

extern int16_t VBAT_ADCVal;

void basicio_init(void);


#endif




